#include "KControl.h"

KControl::KControl(unsigned priority)
{
	m_Priority = priority;

	ZeroMemory(&m_Bounds, sizeof(KBounds));
	ZeroMemory(&m_Rect, sizeof(RECT));
}

KControl::~KControl()
{
}

void KControl::SetBounds(int x, int y, int w, int h)
{
	m_Bounds.x = x;
	m_Bounds.y = y;
	m_Bounds.w = w;
	m_Bounds.h = h;

	m_Rect.left = x;
	m_Rect.top = y;
	m_Rect.right = x + w;
	m_Rect.bottom = y + h;
}

bool KControl::Paint( KMessage & rMsg )
{
	return false;
}

bool KControl::MouseMove( KMessage & rMsg )
{
	int x = LOWORD(rMsg.lParam);
	int y = HIWORD(rMsg.lParam);

	if( x >= m_Rect.left && x <= m_Rect.right 
		&& y >= m_Rect.top && y <= m_Rect.bottom )
	{
		rMsg.sender = this;
		return true;
	}
	return false;
}

bool KControl::LButtonDown( KMessage & rMsg )
{
	int x = LOWORD(rMsg.lParam);
	int y = HIWORD(rMsg.lParam);

	if( x >= m_Rect.left && x <= m_Rect.right 
		&& y >= m_Rect.top && y <= m_Rect.bottom )
	{
		rMsg.sender = this;
		return true;
	}
	return false;
}

bool KControl::LButtonUp( KMessage & rMsg )
{
	int x = LOWORD(rMsg.lParam);
	int y = HIWORD(rMsg.lParam);

	if( x >= m_Rect.left && x <= m_Rect.right 
		&& y >= m_Rect.top && y <= m_Rect.bottom )
	{
		rMsg.sender = this;
		return true;
	}
	return false;
}

bool KControl::RButtonDown( KMessage & rMsg )
{
	int x = LOWORD(rMsg.lParam);
	int y = HIWORD(rMsg.lParam);

	if( x >= m_Rect.left && x <= m_Rect.right 
		&& y >= m_Rect.top && y <= m_Rect.bottom )
	{
		rMsg.sender = this;
		return true;
	}
	return false;
}

bool KControl::RButtonUp( KMessage & rMsg )
{
	int x = LOWORD(rMsg.lParam);
	int y = HIWORD(rMsg.lParam);

	if( x >= m_Rect.left && x <= m_Rect.right 
		&& y >= m_Rect.top && y <= m_Rect.bottom )
	{
		rMsg.sender = this;
		return true;
	}
	return false;
}

bool KControl::OtherMsg( KMessage & rMsg )
{
	return false;
}